//
//  WorldDetailViewController.m
//  MemoryTravel
//
//  Created by dllo on 15/12/24.
//  Copyright © 2015年 fcx. All rights reserved.
//

#import "WorldDetailViewController.h"

@interface WorldDetailViewController ()<UITableViewDataSource,UITableViewDelegate,WorldDetailDelegete>
@property(nonatomic,strong)UITableView *myTableView;
@property (nonatomic, retain) NSMutableArray *myArray;

@end

@implementation WorldDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.myArray = [NSMutableArray array];
    
    self.myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, Width, Height - 49 ) style:UITableViewStylePlain];
    [self.view addSubview:self.myTableView];
    self.myTableView.dataSource = self;
    self.myTableView.delegate = self;
    self.myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    [self.myTableView registerClass:[WorldDetailTableViewCell class] forCellReuseIdentifier:@"cell"];
    
    [self getAFNetWorkingData];
    
    // Do any additional setup after loading the view.
}

- (void)getAFNetWorkingData{
    
    NSString *url = [NSString stringWithFormat:@"http://chanyouji.com/api/destinations/%@.json", self.aModel.nameId];
    [AppTools getDataWithUrlStr:url andBlock:^(id result) {
        
        NSMutableArray *bigArray = [NSMutableArray arrayWithArray:result];
        for (NSMutableDictionary *dic in bigArray) {
            WorldModel *foreignModel = [[WorldModel alloc] initWithDictionary:dic];
            [self.myArray addObject:foreignModel];
        }
        [self.myTableView reloadData];
    }];
    
    
    
    
    
}



-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSLog(@"%ld",self.myArray.count);
    return self.myArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"cell";
    
    WorldDetailTableViewCell *detailCell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    // 取消点击置灰效果
    detailCell.selectionStyle = UITableViewCellSelectionStyleNone;
    detailCell.delegete = self;
    //    detailCell.cellDelegate = self;
    
    WorldModel *foreignModel = [self.myArray objectAtIndex:indexPath.row];
    
    detailCell.aModel = foreignModel;
    
    return detailCell;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 300 ;
}

-(void)pushToViewControllerTag:(NSInteger)tag NameId:(NSString *)nameId name:(NSString *)name{
    if (tag == 1001) {
        
        DBYlineViewController *foreignRoadVC = [[DBYlineViewController alloc] init];
        
        [self.navigationController pushViewController:foreignRoadVC animated:YES];
        
        DBYRoadModel *roadModel = [[DBYRoadModel alloc] init];
        
        foreignRoadVC.model = roadModel;
        
        roadModel.nameId = nameId;
        
        roadModel.name = name;
        
    }else if (tag == 1002){
        
        DBYSubjectViewController *subjectVC = [[DBYSubjectViewController alloc] init];
        
        DBYRoadModel *roadModel = [[DBYRoadModel alloc] init];
        
        roadModel.nameId = nameId;
        
        roadModel.name = name;
        
        subjectVC.dURL = nameId;
        
        [self.navigationController pushViewController:subjectVC animated:YES];
        
        
    }else if(tag == 1003)
    {
        
       DBYDestinationViewController  *destinVc = [[DBYDestinationViewController alloc] init];
        
        DBYRoadModel *roadModel = [[DBYRoadModel alloc] init];
        
        destinVc.roadModel = roadModel;
        
        roadModel.name = name;
        
        roadModel.nameId = nameId;
        
        [self.navigationController pushViewController:destinVc animated:YES];

        
        
        
    }
    
    
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
